package org.sdp.pearproject.controller;


import org.sdp.pearproject.controller.custom.*;
import org.sdp.pearproject.dto.request.*;
import org.sdp.pearproject.dto.response.*;

import java.util.List;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName: OrganizationController
 * @Description:
 * @Author: SDP
 * @Date: 2022-07-04
 * @Version: 1.0
 * Table: pear_organization
 * Comment:
 * 组织表
 */
@RestController
@RequestMapping(value = "/organization")
public class OrganizationController extends OrganizationCustomController {
    static {
        addRequestClass("organization", "add", "organizationController", OrganizationController.class, OrganizationAddRequest.class);
        addRequestClass("organization", "add_encrypt", "organizationController", OrganizationController.class, OrganizationAddRequest.class);

        addRequestClass("organization", "update", "organizationController", OrganizationController.class, OrganizationUpdateRequest.class);
        addRequestClass("organization", "update_encrypt", "organizationController", OrganizationController.class, OrganizationUpdateRequest.class);

        addRequestClass("organization", "delete", "organizationController", OrganizationController.class, OrganizationDeleteRequest.class);
        addRequestClass("organization", "delete_encrypt", "organizationController", OrganizationController.class, OrganizationDeleteRequest.class);

        addRequestClass("organization", "query", "organizationController", OrganizationController.class, OrganizationQueryRequest.class);
        addRequestClass("organization", "query_encrypt", "organizationController", OrganizationController.class, OrganizationQueryRequest.class);

        addRequestClass("organization", "list", "organizationController", OrganizationController.class, OrganizationQueryRequest.class);
        addRequestClass("organization", "list_encrypt", "organizationController", OrganizationController.class, OrganizationQueryRequest.class);

        addRequestClass("organization", "count", "organizationController", OrganizationController.class, OrganizationQueryRequest.class);
        addRequestClass("organization", "count_encrypt", "organizationController", OrganizationController.class, OrganizationQueryRequest.class);

        addRequestClass("organization", "stat", "organizationController", OrganizationController.class, OrganizationQueryRequest.class);
        addRequestClass("organization", "stat_encrypt", "organizationController", OrganizationController.class, OrganizationQueryRequest.class);

    }

    @PostMapping("/add")
    public Integer addOrganization(@MixRequestBody OrganizationAddRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("organization", "add", request, callFromEncrypt);
        return super.addOrganization(request);
    }

    @PostMapping("/add_encrypt")
    public String addOrganizationEncrypt(@MixRequestBody String strRequest) throws Exception {
        OrganizationAddRequest request = (OrganizationAddRequest) super.decrypt("organization", "add_encrypt", strRequest, OrganizationAddRequest.class);
        Integer result = addOrganization(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/update")
    public Integer updateOrganization(@MixRequestBody OrganizationUpdateRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("organization", "update", request, callFromEncrypt);
        return super.updateOrganization(request);
    }

    @PostMapping("/update_encrypt")
    public String updateOrganizationEncrypt(@MixRequestBody String strRequest) throws Exception {
        OrganizationUpdateRequest request = (OrganizationUpdateRequest) super.decrypt("organization", "update_encrypt", strRequest, OrganizationUpdateRequest.class);
        Integer result = updateOrganization(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/delete")
    public Integer deleteOrganization(@MixRequestBody OrganizationDeleteRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("organization", "delete", request, callFromEncrypt);
        return super.deleteOrganization(request);
    }

    @PostMapping("/delete_encrypt")
    public String deleteOrganizationEncrypt(@MixRequestBody String strRequest) throws Exception {
        OrganizationDeleteRequest request = (OrganizationDeleteRequest) super.decrypt("organization", "delete_encrypt", strRequest, OrganizationDeleteRequest.class);
        Integer result = deleteOrganization(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/query")
    public OrganizationQueryResponse queryOrganization(@MixRequestBody OrganizationQueryRequest request, Integer callFromEncrypt) throws Exception {
      super.fixRequest("organization", "query", request, callFromEncrypt);
      return super.queryOrganization(request);
    }

    @PostMapping("/query_encrypt")
    public String queryOrganizationEncrypt(@MixRequestBody String strRequest) throws Exception {
        OrganizationQueryRequest request = (OrganizationQueryRequest) super.decrypt("organization", "query_encrypt", strRequest, OrganizationQueryRequest.class);
        OrganizationQueryResponse result = queryOrganization(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/list")
    public List<OrganizationQueryResponse> listOrganization(@MixRequestBody OrganizationQueryRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("organization", "list", request, callFromEncrypt);
        if (super.needTotal("organization", "list", request)) {
            super.setTotal("organization", "list", request, super.countOrganization(request));
        }
        return super.listOrganization(request);
    }

    @PostMapping("/list_encrypt")
    public String listOrganizationEncrypt(@MixRequestBody String strRequest) throws Exception {
        OrganizationQueryRequest request = (OrganizationQueryRequest) super.decrypt("organization", "list_encrypt", strRequest, OrganizationQueryRequest.class);
        List<OrganizationQueryResponse> result = listOrganization(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/count")
    public Integer countOrganization(@MixRequestBody OrganizationQueryRequest request, Integer callFromEncrypt) throws Exception {
      super.fixRequest("organization", "count", request, callFromEncrypt);
      return super.countOrganization(request);
    }


    @PostMapping("/count_encrypt")
    public String countOrganizationEncrypt(@MixRequestBody String strRequest) throws Exception {
        OrganizationQueryRequest request = (OrganizationQueryRequest) super.decrypt("organization", "count_encrypt", strRequest, OrganizationQueryRequest.class);
        Integer result = countOrganization(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/stat")
    public BaseStatResponse statOrganization(@MixRequestBody OrganizationQueryRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("organization", "stat", request, callFromEncrypt);
        return super.statOrganization(request);
    }

    @PostMapping("/stat_encrypt")
    public String statOrganizationEncrypt(@MixRequestBody String strRequest) throws Exception {
        OrganizationQueryRequest request = (OrganizationQueryRequest) super.decrypt("organization", "stat_encrypt", strRequest, OrganizationQueryRequest.class);
        BaseStatResponse result = statOrganization(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }


}
